package com.zhiyou100.loans.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

public class UrlFilter implements Filter{

	@Override
	public void doFilter(ServletRequest req, ServletResponse arg1, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
		//获取到项目的根路径，项目的全路径，然后做一个共享
		System.out.println(request.getServerName());
		System.out.println(request.getServerPort());
		System.out.println(request.getServletContext().getContextPath());
		System.out.println(request.getProtocol());
		//拼接处路径：http://localhost:8080/loans/
		String url = request.getProtocol()+"://"+request.getServerName()+":"+request.getServerPort()+request.getServletContext().getContextPath()+"/";
		request.getSession().setAttribute("url", url);
		chain.doFilter(request, arg1);
	}

}
